Module netutils
[hide private]

Module netutils

source code

This library can be used to get all kind of network/tcp information, such as getting the Operating system name, checking if a MAC Address is valid, check if an IP Address is valid etc.



Classes [hide private]
  DNSResolver
  IpResolver
Functions [hide private]
string
getHostAddress(dnsName, defaultValue=None)
Resolves the host name to the IP Address in DNS table.
source code
string
getHostName(ipAddress, defaultValue=None)
Resolves the IP address to the host name in the DNS table.
source code
Boolean
isValidIp(ipAddr)
Checks whether the given IP address is valid.
source code
 
convertAsciiCodesToHex(asciiSeq)
str -> str
source code
string
parseMac(origmac)
Parses the given macAddress and converts it to the system format XXXXXXXXXXXX, where X is an uppercase hexadecimal digit.
source code
integer
isValidMac(mac, ifType='ethernetCsmacd')
Checks whether the specified MAC address is valid.
source code
string
parseNetMask(origmask)
Parses the supplied network mask into the common format of %d.%d.%d.%d
source code
string
getOSName(client, cmd)
Retrieves the operating system name.
source code
int
isLocalIp(ip)
Checks whether the specified IP is loopback (assumes the given IP is *valid*).
source code
 
getAvailableProtocols(Framework, PROT_TYPE, IP, DOMAIN) source code
 
doHttpGet(url, timeout=20000, requestedData='body', headerName=None)
Performs HTTP(S) Connection to the specified URL
source code
 
checkTcpConnectivity(ipAddress, portNumber, timeout)
Checks the TCP connection to the given ipAddress on the given port.
source code
 
pingIp(Framework, ipAddress, timeout)
Ping the specified device
source code
 
isIpBroadcast(ipAddress, netmask) source code
 
isIpAnycast(ipAddress, interfaceName) source code
 
getPortDescription(portNumber, portType)
Return port name for the given port number and type.
source code
 
getDBConnection(userName, password, driverName, connectionURL)
Return PyConnection to the database (see Jython's zxJDBC description)
source code
 
getLeadingOnesCount(number) source code
 
getShortMask(netmask) source code
string
decodeSubnetMask(routingPrefix, isIpV4=1)
Returns: subnet mask
source code
string
obtainDotDecimalTuple(cidrNotationBlock)
Returns: subnet mask in dot-decimal notation or None
source code
 
negateNetMask(mask) source code
Function Details [hide private]

getHostAddress(dnsName, defaultValue=None)

source code 

Resolves the host name to the IP Address in DNS table. On failure to resolve the name, the default value parameter is returned.

Parameters:
  • dnsName (string) - host name to resolve
  • defaultValue - the value to return if the host name cannot be resolved
Returns: string
IP address of the resolved host name

getHostName(ipAddress, defaultValue=None)

source code 

Resolves the IP address to the host name in the DNS table. On failure to resolve the address the , default value parameter is returned.

Parameters:
  • ipAddress (string) - IP address to resolve
  • defaultValue - the value to return if the address cannot be resolved
Returns: string
host name of the resolved IP address

isValidIp(ipAddr)

source code 

Checks whether the given IP address is valid.

Parameters:
  • ipAddr (string) - IP address to check
Returns: Boolean
true if the IP is valid, else false

parseMac(origmac)

source code 

Parses the given macAddress and converts it to the system format XXXXXXXXXXXX, where X is an uppercase hexadecimal digit.

Parameters:
  • origmac (string) - raw or formated MAC address
Returns: string
parsed MAC address in the converted format
Raises:
  • ValueError - If address has invalid format

isValidMac(mac, ifType='ethernetCsmacd')

source code 

Checks whether the specified MAC address is valid.

Parameters:
  • mac (string) - MAC address to check
Returns: integer
1 if MAC is valid, 0 otherwise

parseNetMask(origmask)

source code 

Parses the supplied network mask into the common format of %d.%d.%d.%d

Parameters:
  • origmask (string) - NetMask address to parse
Returns: string
parsed NetMask address

getOSName(client, cmd)

source code 

Retrieves the operating system name.

Parameters:
  • client (shellClinet) - pre-connected shell client
Returns: string
operating system name

isLocalIp(ip)

source code 

Checks whether the specified IP is loopback (assumes the given IP is *valid*). Loopback IPs are 0.0.0.0 or any IP which starts with '127'

Parameters:
  • ip (String) - IP address to check
Returns: int
1 if the IP is loopback, else 0

doHttpGet(url, timeout=20000, requestedData='body', headerName=None)

source code 

Performs HTTP(S) Connection to the specified URL

Returns data according to the requestedData flag:
  'body': Full Response Body as String
  'header': Returns the response header with the specified headerName

checkTcpConnectivity(ipAddress, portNumber, timeout)

source code 

Checks the TCP connection to the given ipAddress on the given port.

Parameters:
  • ipAddress (String) - IP address of the remote computer to check
  • portNumber (int) - The port number to check
  • timeout (int @return 1 if the TCP connection succeeded, else) - connection timeout in millisecondes

pingIp(Framework, ipAddress, timeout)

source code 

Ping the specified device

Parameters:
  • ipAddress (string) - the IP address to ping
  • timeout (int) - ping timeout in milliseconds
Returns:
1 if the machine is pingable, else 0

getPortDescription(portNumber, portType)

source code 

Return port name for the given port number and type.

Parameters:
  • portNumber - The port number
  • portType - The port type (TCP / UDP)
Returns:
String the description

getDBConnection(userName, password, driverName, connectionURL)

source code 

Return PyConnection to the database (see Jython's zxJDBC description)

Parameters:
  • userName - the username to connect to DB with
  • password - the password to connect to DB with
  • driverName - name of the driver to connect through
Returns:
com.ziclix.python.sql.PyConnection

decodeSubnetMask(routingPrefix, isIpV4=1)

source code 
Parameters:
  • routingPrefix - routing prefix - natural numbers
  • isIpV4 - if true dot-decimal mask will be used instead of IpV6
Returns: string
subnet mask

Precondition: IpV6 is not supported Decode routing prefix to IpV4 (dotDecimal) mask or IpV6 mask

obtainDotDecimalTuple(cidrNotationBlock)

source code 
Parameters:
  • cidrNotationAddress - address string in CIDR notation (xxx.xxx.xxx.xxx/xx)
Returns: string
subnet mask in dot-decimal notation or None

Precondition: only IPv4 is supported Obtain subnet mask from cidr notation.




Documentation Feedback
Copyright 2010 Hewlett-Packard Development Company, L.P.